<?php
/**
 * Created by PhpStorm.
 * User: adminstrator
 * Date: 2018/2/8
 * Time: 16:35
 */
header("Content-type:text/html;charset=utf-8");
date_default_timezone_set('PRC');
include_once("./Db_pdo.class.php"); 
echo '<pre>';
//$DB=new Db_pdo("cxh_v3","cxhv3","cxhv3pwd!@#");
$DB=new Db_pdo("aisiqu","root","root");

 
// $data = unserialize(file_get_contents('data.txt')); 

// print_r($data);

// $sql = "select * from aq_area limit 150000";

// $data = $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC);  

// // print_r($data);
// // exit;

// file_put_contents('linshis.txt',serialize($data));
// exit;
$data = unserialize(file_get_contents('linshis.txt')); 
// print_r($data);
// exit;
$arr = array_chunk($data, 20000);

foreach($arr as $v) {
	$sql = "INSERT INTO aq_area (`area_name`,`full_name`,`level`,`parent_id`,`province_id`) VALUES ";
	foreach ($v as $value) { 
		$param['area_name'] = $value['area_name'];
		$param['full_name'] =$value['full_name'];
		$param['level'] = $value['level'];
		$param['parent_id'] =$value['parent_id'];
		$param['province_id'] =$value['province_id'];
		// $param['member_id'] = $value['member_id'];
		// $param['ctime'] = $value['ctime']-86400;
		// $s.='(null,3,'.$value['id'].','.$value['need_back'].',0,0,'.$value['user_id'].','.$value['back_time'].'),';
		// echo $s;
	    $values="('".implode("','",array_values($param))."'),";
	    // echo $values;
	    $sql .= $values;
	}
	$sql = rtrim($sql, ",");

	$DB->db->query($sql);
	// return ;
}
exit;
// print_r($data);




// $sql ='
// SELECT 
// 	member_id,
// 	sum(apla_totel_retime) as atime,
// 	sum(apla_re_money)
// FROM
// 	ims_cxh_apply_subsidy_agent
// WHERE
// 	apla_status = 1
// 	and apla_totel_retime >0
// GROUP BY
// 	member_id';
// $cxhusers = $DB->new_query($sql);
// $cxhusers = $cxhusers->fetchAll(PDO::FETCH_ASSOC);  
// // print_r($cxhusers);
// $arr =array();
// foreach ($cxhusers as $key => $value) {
// 	$sql1 ='SELECT
// 	member_id,
// 	count(*) as btime,
// 	-- sum(apb_money) + sum(apb_fee) + sum(apb_intgral),
// 	max(apb_money) as moneys,
// 	min(ctime) as ctime
// FROM
// 	ims_cxh_apply_subsidy_back
// WHERE
// 	apb_type = 2
// 	and member_id ='.$value['member_id'].'
//  GROUP BY
// 	member_id';
// 	$data = $DB->new_query($sql1);
// 	$data = $data->fetchAll(PDO::FETCH_ASSOC);  

// 	if($value['atime']-$data['0']['btime']==1){
// 		$arr[] = $data['0'];
// 	}
	
// }

// file_put_contents('linshi.txt',serialize($arr));
// $ticket_log = unserialize(file_get_contents('linshi.txt')); 
// $arr = array_chunk($ticket_log, 20000);
// foreach($arr as $v) {
// 	$sql = "INSERT INTO ims_cxh_apply_subsidy_back (`apb_type`,`bus_id`,`apb_money`,`apb_intgral`,`apb_fee`,`member_id`,`ctime`) VALUES ";
// 	foreach ($v as $value) { 
// 		$param['apb_type'] = 2;
// 		$param['bus_id'] =0;
// 		$param['apb_money'] = $value['moneys'];
// 		$param['apb_intgral'] =0;
// 		$param['apb_fee'] =0;
// 		$param['member_id'] = $value['member_id'];
// 		$param['ctime'] = $value['ctime']-86400;
// 		// $s.='(null,3,'.$value['id'].','.$value['need_back'].',0,0,'.$value['user_id'].','.$value['back_time'].'),';
// 		// echo $s;
// 	    $values="('".implode("','",array_values($param))."'),";
// 	    // echo $values;
// 	    $sql .= $values;
// 	}
// 	$sql = rtrim($sql, ",");
// 	// echo $sql;
// 	$DB->db->query($sql);
// 	// return ;
// }
// print_r($ticket_log);
// print_r($arr);










